<?php 
header("Content-type: text/html; charset=utf-8"); 
$conn=@mysql_connect('localhost','root','')
   Or die('数据库无法连接！');
@mysql_select_db('neu-video',$conn)
Or die('数据库不存在！');
mysql_set_charset('utf8');
$sql='select * from users';

$result=mysql_query($sql,$conn);
// while($result && ($row=mysql_fetch_assoc($result))!==FALSE)
// {
//   echo $row['uname'].'<br>';
// }
 $users=fetch_array($result);
 
//var_dump($users);
 echo '<table border="1">';
 echo '<caption>用户列表</caption>';
 echo '<tr><th>用户编号</th><th>用户名</th><th>性别</th><th>生日</th><th>爱好</th><th>学历</th><th>自我介绍</th><th>头像</th></tr>';
 foreach ($users as $index=>$one) {
    echo '<tr>';
 	echo '<td>'.($index+1).'</td>';
 	echo '<td>'.$one['uname'].'</td>';
 	if($one['gender']==1){$sex='男';}
    else{$sex='女';}
 	echo '<td>'.$sex.'</td>';
 	echo '<td>'.$one['birthdate'].'</td>';
    echo '<td>'.$one['hobby'].'</td>';
    echo '<td>'.$one['degree'].'</td>';
    echo '<td>'.$one['intro'].'</td>';
    echo '<td>'.$one['pic'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';




 $sql1='select * from videotype';
$result1=mysql_query($sql1,$conn);
 $videotype=fetch_array($result1);

  echo '<table border="1">';
   echo '<caption>视频类型</caption>';
 echo '<tr><th>种类编号</th><th>种类名称</th></tr>';
 foreach ($videotype as $index=>$one) {
    echo '<tr>';
 	echo '<td>'.($index+1).'</td>';
 	echo '<td>'.$one['typename'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';

$sql2='select * from videos left join videotype on videos.tid=videotype.tid';
$result2=mysql_query($sql2,$conn);
 $videos=fetch_array($result2);

  echo '<table border="1">';
   echo '<caption>视频列表</caption>';
  echo '<tr><th>视频编号</th><th>视频名称</th><th>类型编号</th><th>类型名称</th><th>海报</th><th>内容简介</th><th>添加日期</th><th>上传用户</th><th>点击率</th><th>下载量</th><th>下载地址</th></tr>';
 foreach ($videos as $one) {
    echo '<tr>';
 	echo '<td>'.$one['vid'].'</td>';
 	echo '<td>'.$one['videoname'].'</td>';
 	echo '<td>'.$one['tid'].'</td>';
 	echo '<td>'.$one['typename'].'</td>';
    echo '<td>'.$one['pic'].'</td>';
    echo '<td>'.$one['intro'].'</td>';
    echo '<td>'.$one['uploaddate'].'</td>';
    echo '<td>'.$one['uploadadmin'].'</td>';
    echo '<td>'.$one['hittimes'].'</td>';
    echo '<td>'.$one['downtimes'].'</td>';
    echo '<td>'.$one['address'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';

$sql3='select * from admins';
$result3=mysql_query($sql3,$conn);
 $admins=fetch_array($result3);

  echo '<table border="1">';
   echo '<caption>管理员表</caption>';
 echo '<tr><th>管理员编号</th><th>管理员名</th><th>密码</th></tr>';
 foreach ($admins as $index=>$one) {
    echo '<tr>';
 	echo '<td>'.($index+1).'</td>';
 	echo '<td>'.$one['adminname'].'</td>';
 	echo '<td>'.$one['password'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';

 $sql4='select * from comments';
$result4=mysql_query($sql4,$conn);
 $comments=fetch_array($result4);

  echo '<table border="1">';
   echo '<caption>评论信息表</caption>';
 echo '<tr><th>评论编号</th><th>评论内容</th><th>评论日期</th><th>评论用户</th><th>评论视频</th></tr>';
 foreach ($comments as $index=>$one) {
    echo '<tr>';
 	echo '<td>'.($index+1).'</td>';
 	echo '<td>'.$one['content'].'</td>';
 	echo '<td>'.$one['cdate'].'</td>';
 	echo '<td>'.$one['uid'].'</td>';
 	echo '<td>'.$one['vid'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';
 
 $sql5='select * from levels';
$result5=mysql_query($sql5,$conn);
 $levels=fetch_array($result5);

  echo '<table border="1">';
   echo '<caption>视频评分表</caption>';
 echo '<tr><th>级别编号</th><th>视频编号</th><th>打分用户</th><th>评分</th></tr>';
 foreach ($levels as $index=>$one) {
    echo '<tr>';
 	echo '<td>'.($index+1).'</td>';
 	echo '<td>'.$one['vid'].'</td>';
 	echo '<td>'.$one['uid'].'</td>';
 	echo '<td>'.$one['score'].'</td>';
 	echo '</tr>';
 }
 echo '</table>';


function fetch_array($results){
   $arrs=array();
   while($results && ($row=mysql_fetch_assoc($results))!==FALSE)
{
     $arrs[]=$row;
}
	return $arrs;
}
 ?>

